<?php

/**
 * This is the model class for table "cctvcamera".
 *
 * The followings are the available columns in table 'cctvcamera':
 * @property string $CompanyID
 * @property integer $CompanyBranchID
 * @property string $ComputerName
 * @property string $CameraName
 * @property string $CameraURL
 * @property integer $PictureWidth
 * @property integer $PictureHeight
 * @property integer $IPCameraTypeID
 * @property integer $isOriginalSize
 * @property integer $isActive
 * @property string $CreatedBy
 * @property string $CreatedOn
 * @property string $LastUpdateBy
 * @property string $LastUpdateOn
 *
 * The followings are the available model relations:
 * @property Cctvcameratypemaster $iPCameraType
 * @property Invcompany $company
 * @property Invcompanybranch $companyBranch
 * @property Cctvmappingcamera[] $cctvmappingcameras
 * @property Cctvmappingcamera[] $cctvmappingcameras1
 * @property Cctvmappingcamera[] $cctvmappingcameras2
 * @property Cctvmappingcamera[] $cctvmappingcameras3
 */
class Cctvcamera extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'cctvcamera';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('companyid, companybranchid, computername, cameraname', 'required'),
			array('companybranchid, picturewidth, pictureheight, ipcameratypeid, isoriginalsize, isactive', 'numerical', 'integerOnly'=>true),
			array('companyid', 'length', 'max'=>20),
			array('computername', 'length', 'max'=>100),
			array('cameraname, createdby, lastupdateby', 'length', 'max'=>50),
			array('cameraurl', 'length', 'max'=>500),
			array('createdon, lastupdateon', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('companyid, companybranchid, computername, cameraname, cameraurl, picturewidth, pictureheight, ipcameratypeid, isoriginalsize, isactive, createdby, createdon, lastupdateby, lastupdateon', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'iPCameraType' => array(self::BELONGS_TO, 'Cctvcameratypemaster', 'ipcameratypeid'),
			'company' => array(self::BELONGS_TO, 'Invcompany', 'companyid'),
			'companyBranch' => array(self::BELONGS_TO, 'Invcompanybranch', 'companybranchid'),
			'cctvmappingcameras' => array(self::HAS_MANY, 'Cctvmappingcamera', 'companyid'),
			'cctvmappingcameras1' => array(self::HAS_MANY, 'Cctvmappingcamera', 'companybranchid'),
			'cctvmappingcameras2' => array(self::HAS_MANY, 'Cctvmappingcamera', 'computername'),
			'cctvmappingcameras3' => array(self::HAS_MANY, 'Cctvmappingcamera', 'cameraname'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'companyid' => 'Company',
			'companybranchid' => 'Company Branch',
			'computername' => 'Computer Name',
			'cameraname' => 'Camera Name',
			'cameraurl' => 'Camera Url',
			'picturewidth' => 'Picture Width',
			'pictureheight' => 'Picture Height',
			'ipcameratypeid' => 'Ipcamera Type',
			'isoriginalsize' => 'Is Original Size',
			'isactive' => 'Is Active',
			'createdby' => 'Created By',
			'createdon' => 'Created On',
			'lastupdateby' => 'Last Update By',
			'lastupdateon' => 'Last Update On',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('companyid',$this->companyid,true);
		$criteria->compare('companybranchid',$this->companybranchid);
		$criteria->compare('computername',$this->computername,true);
		$criteria->compare('cameraname',$this->cameraname,true);
		$criteria->compare('cameraurl',$this->cameraurl,true);
		$criteria->compare('picturewidth',$this->picturewidth);
		$criteria->compare('pictureheight',$this->pictureheight);
		$criteria->compare('ipcameratypeid',$this->ipcameratypeid);
		$criteria->compare('isoriginalsize',$this->isoriginalsize);
		$criteria->compare('isactive',$this->isactive);
		$criteria->compare('createdby',$this->createdby,true);
		$criteria->compare('createdon',$this->createdon,true);
		$criteria->compare('lastupdateby',$this->lastupdateby,true);
		$criteria->compare('lastupdateon',$this->lastupdateon,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return Cctvcamera the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
